package me.cxlr.qinlauncher2.view.settings;

import android.os.Bundle;

import androidx.navigation.fragment.NavHostFragment;
import androidx.preference.DropDownPreference;
import androidx.preference.PreferenceFragmentCompat;

import me.cxlr.qinlauncher2.R;
import me.cxlr.qinlauncher2.util.ThemeUtil;

/**
 * @author 酷安用户:山轮纸
 */
public class SettingsFragment extends PreferenceFragmentCompat {

    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        setPreferencesFromResource(R.xml.preferences_settings, rootKey);

        // 基础
        DropDownPreference baseSettings = findPreference("base_settings");
        assert baseSettings != null;
        baseSettings.setOnPreferenceClickListener(preference -> {
            NavHostFragment.findNavController(SettingsFragment.this).navigate(R.id.action_settingsFragment_to_baseSettingsFragment);
            return true;
        });

        // 桌面
        DropDownPreference desktopSettings = findPreference("desktop_settings");
        assert desktopSettings != null;
        desktopSettings.setOnPreferenceClickListener(preference -> {
            NavHostFragment.findNavController(SettingsFragment.this).navigate(R.id.action_settingsFragment_to_desktopSettingsFragment);
            return true;
        });

        // 桌面按键
        DropDownPreference keySettings = findPreference("key_settings");
        assert keySettings != null;
        keySettings.setOnPreferenceClickListener(preference -> {
            NavHostFragment.findNavController(SettingsFragment.this).navigate(R.id.action_settingsFragment_to_keySettingsFragment);
            return true;
        });

        // 应用抽屉
        DropDownPreference appDrawerSettings = findPreference("app_drawer_settings");
        assert appDrawerSettings != null;
        appDrawerSettings.setOnPreferenceClickListener(preference -> {
            NavHostFragment.findNavController(SettingsFragment.this).navigate(R.id.action_settingsFragment_to_drawerSettingsFragment);
            return true;
        });

        // 更新信息
        DropDownPreference versionMessage = findPreference("about_version_message");
        assert versionMessage != null;
        versionMessage.setOnPreferenceClickListener(preference -> {
            NavHostFragment.findNavController(SettingsFragment.this).navigate(R.id.action_settingsFragment_to_versionMessageFragment);
            return true;
        });

        // 关于作者
        DropDownPreference aboutAuthor = findPreference("about_author");
        assert aboutAuthor != null;
        aboutAuthor.setOnPreferenceClickListener(preference -> {
            NavHostFragment.findNavController(SettingsFragment.this).navigate(R.id.action_settingsFragment_to_aboutAuthorFragment);
            return true;
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        ThemeUtil.initTheme();
    }
}